package main

import (
	"fmt"
	"go_data_structures_and_algorithms/system_class/section8/pojo"
	"math"
	"sort"
)

// Heapp是小根堆
func main() {
	//heapp := pojo1.NewHeapp()
	//heapp.Add(1)
	//heapp.Add(5)
	//heapp.Add(3)
	//heapp.Add(0)
	//heapp.Add(2)
	//
	//fmt.Println(heapp)
	i := [][2]int{{4, 5}, {4, 6}, {2, 3}, {1, 7}}
	MaximumNumberOfLineSegments(i)
}

func MaximumNumberOfLineSegments(lineNumbers [][2]int) {
	lines := []*pojo.Line{}

	max := 0
	for i := 0; i < len(lineNumbers); i++ {
		lines = append(lines, pojo.NewLine(lineNumbers[i][0], lineNumbers[i][1]))
	}

	sort.Sort(pojo.Lines(lines))
	heapp := pojo.NewHeapp()
	for i := 0; i < len(lines); i++ {
		fmt.Println(i, lines[i].Start, lines[i].End)
		for !heapp.IsEmpty() && lines[i].Start > heapp.Peek() {
			heapp.Poll()
		}

		heapp.Add(lines[i].End)
		max = int(math.Max(float64(heapp.GetSize()), float64(max)))
	}

	fmt.Println(max)
}
